package com.viewpagertext.DBHelper.Dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;

import com.viewpagertext.Model.RecentPlay;
import com.viewpagertext.json.StarredSong;

import java.util.List;

@Dao
public interface RecentPlayDao {

    // 插入播放记录
    @Insert
    public void insertRecentPlay(RecentPlay recentPlay);

    // 删除最早的记录
    @Query("DELETE FROM RecentPlay WHERE id IN (SELECT id FROM RecentPlay ORDER BY id ASC LIMIT 1)")
    void deleteOldestIfLimitExceeded();

    //获取记录数量
    @Query("SELECT COUNT(*) FROM RecentPlay")
    int getRecordCount();

    // 根据id删除记录
    @Query("DELETE FROM RecentPlay WHERE id = :id")
    public void deleteRecentPlayById(int id);

    // 获取所有最近播放记录
    @Query("SELECT * FROM RecentPlay")
    List<RecentPlay> getAllRecentPlay();

    // 根据Name和singer搜索
    @Query("SELECT * FROM RecentPlay WHERE name = :name AND singer = :singer")
    RecentPlay getRecentPlayByNameAndSinger(String name, String singer);

    //根据name和singer删除最近播放记录
    @Query("DELETE FROM RecentPlay WHERE name = :name AND singer = :singer")
    void deleteRecentPlayByNameAndSinger(String name, String singer);

    @Query("SELECT * FROM RecentPlay ORDER BY id DESC LIMIT 1")
    RecentPlay getFirstSong();

}
